<?php

namespace app\service\controller;

use app\common\controller\ServiceOauth;
use external\SFTools;
use think\response\Json;

class Oauth extends ServiceOauth {
    public function initialize() {
        parent::initialize();
    }

    /**
     * 获取订单列明细
     * @param   string  fccode			经销商编码
     * @param   string  phone			电话号码
     * @return  json                    Json对象 ( status / code / msg / data )
     */
    public function getCodeInfo() {
        $fccode = htmlspecialchars(input("post.fccode"));
        $phone = htmlspecialchars(input("post.phone"));
        $oauthLogic = new \backend\logic\OauthLogic;
        $result = $oauthLogic->getOauthFindBuyFccodeAndPhone($fccode, $phone);
        if (empty($result['error_code'])) {
            return SFTools::pullJson(1, NULL, $result);
        }
        else {
            return SFTools::pullJson(-1, $result['error_code'], $result['data']);
        }
    }

    /**
     * 绑定经销商编码
     * @param   string  fccode			经销商编码
     * @param   string  phone			电话号码
     * @param   string  cur_code		验证码
     * @param   string  pow_code		授权码
     * @return  json                    Json对象 ( status / code / msg / data )
     */
    public function toRegister() {
        $fccode = htmlspecialchars(input("post.fccode"));
        $phone = htmlspecialchars(input("post.phone"));
        $cur_code = htmlspecialchars(input("post.cur_code"));
        $pow_code = htmlspecialchars(input("post.pow_code"));
        $oauthLogic = new \backend\logic\OauthLogic;
        $result = $oauthLogic->toRegisterBuyCode($fccode, $phone, $cur_code, $pow_code);
        if (empty($result['error_code'])) {
            return SFTools::pullJson(1, NULL, $result);
        }
        else {
            return SFTools::pullJson(-1, $result['error_code'], $result['data']);
        }
    }
}
